Skip to content

feat: pharn verify-archive checks a local pharn-oss archive as an install would (CORE-387) - #449

Merged
PrzemekGalarowicz merged 11 commits into
mainfrom
feat/core-387-verify-archive
Nov 25, 2026
Merged

PrzemekGalarowicz merged 11 commits into
mainfrom
feat/core-387-verify-archive

Conversation

@PrzemekGalarowicz

Copy link
Copy Markdown
Member

Refs CORE-380. Builds on CORE-386 (#448, merged and released as 0.21.6), which made the extractor take a buffer.

What

This adds pharn verify-archive <file> [--expect-version X.Y.Z], which checks a local pharn-oss .tar.gz the way an install checks a download. pharn-oss CI can use it to find out that a commit installs before it tags that commit.

  • The same checks as an install. It runs the install path's own extractPharnArchive: both passes, the pharn-install.json parser, and every listed sha256. It also runs the install's two pure reads of the tree:
    • the capability index (manifestCapabilityIndex). Unknown applies tokens get the same warning an install prints, and the check still passes.
    • MIN_CLI, for validity only. A present but unusable MIN_CLI fails the check, which is stricter than install on purpose. No version comparison is made.
  • --expect-version holds SKILLS_VERSION to a version through assertSkillsVersion, a new helper in skills-version.ts. The release check in fetchAt now calls the same helper, and its message is byte-identical.
  • No network, no project, no lock. verifyLocalArchive in repo.ts creates one private pharn-verify-* temp dir, registers it with the clone's exit/fatal-signal backstop, and removes it in a finally.
  • Bounded input. The file is read with readBoundedFile (unchanged): regular file only, capped at MAX_ARCHIVE_BYTES (32 MiB, the download cap), with no FIFO hang. The path is escaped wherever it is printed.
  • Exit codes and errors. Exit 0 prints a one-line summary. Exit 1 goes through CliError:
    • an input problem is error;
    • an archive refusal is failure with Archive <name> refused: <rule + entry>, plus the PHARN_DEBUG hint, or the original error under PHARN_DEBUG=1.
  • One top-level directory is required. The install extractor removes one root component and refuses a selected path that has none above it. A rootless mode would run a selection the install path never runs, so a pass would stop meaning that an install accepts the bytes. The documented command therefore uses git archive --prefix=pharn-oss/. A plain git archive fails with the extractor's refusal plus the fix. The install path's rules are unchanged.
  • No --json, decided at GATE 1: CI gates on the exit code.

For pharn-oss CI (CORE-384, copy this)

Build the archive from the same commit that will be tagged, and pin the pharn version.

PR / push job, checked against the commit's own SKILLS_VERSION:

git archive --prefix=pharn-oss/ --format=tar.gz -o "$RUNNER_TEMP/pharn-oss.tar.gz" HEAD
npx --yes @pharn-dev/pharn@0.22.0 verify-archive "$RUNNER_TEMP/pharn-oss.tar.gz" --expect-version "$(cat SKILLS_VERSION)"

Release job, before the tag is pushed (TAG=v7.25.6, for example):

git archive --prefix=pharn-oss/ --format=tar.gz -o "$RUNNER_TEMP/pharn-oss.tar.gz" HEAD
npx --yes @pharn-dev/pharn@0.22.0 verify-archive "$RUNNER_TEMP/pharn-oss.tar.gz" --expect-version "${TAG#v}"

npx … @0.22.0 works only once this PR is merged and 0.22.0 is published. Node 24.2.0 or newer is required.

Live Done-when (built bundle, node dist/index.js)

$S is a scratch directory. The pharn-oss repo was used read-only (git -C … archive).

$ git -C pharn-oss archive --prefix=pharn-oss/ --format=tar.gz -o $S/a/pharn-oss-main.tar.gz origin/main   # a2cacaef, SKILLS_VERSION 7.25.5
$ node dist/index.js verify-archive $S/a/pharn-oss-main.tar.gz --expect-version 7.25.5
◆  pharn-oss-main.tar.gz: 616 files listed in pharn-install.json, all present and matching their sha256; 35 capabilities; SKILLS_VERSION 7.25.5, as expected; MIN_CLI 0.14.0.
└  Nothing was installed; the temporary directory was removed.
exit=0

$ # (b) (a) extracted, pharn/CONSTITUTION.md altered, repacked (ustar, no xattrs)
$ node dist/index.js verify-archive $S/b/altered.tar.gz
■  ⚠ Archive altered.tar.gz refused: pharn-oss's pharn-install.json declares a sha256 for pharn/CONSTITUTION.md that its bytes do not match; refusing to install. Nothing was written.
●  Re-run with PHARN_DEBUG=1 for full error output.
exit=1

$ curl -sSfL -o $S/c/v7.25.5.tar.gz https://codeload.github.com/pharn-dev/pharn-oss/tar.gz/refs/tags/v7.25.5
$ node dist/index.js verify-archive $S/c/v7.25.5.tar.gz --expect-version 7.25.5
◆  v7.25.5.tar.gz: 616 files listed in pharn-install.json, all present and matching their sha256; 35 capabilities; SKILLS_VERSION 7.25.5, as expected; MIN_CLI 0.14.0.
exit=0
$ node dist/index.js verify-archive $S/c/v7.25.5.tar.gz --expect-version 7.25.6
■  ⚠ Archive v7.25.5.tar.gz refused: it ships SKILLS_VERSION 7.25.5, not 7.25.6 (--expect-version).
exit=1

$ # (d) plain git archive, no --prefix
$ node dist/index.js verify-archive $S/plain/plain.tar.gz
■  ⚠ Archive plain.tar.gz refused: tar entry has no path below the archive root: MIN_CLI. pharn reads archives shaped like GitHub's, with one top-level directory (as `git archive --prefix=` writes); a plain `git archive` has none. Re-create it with `git archive --prefix=pharn-oss/ --format=tar.gz -o pharn-oss.tar.gz HEAD`.
exit=1

The ticket's Done-when names "a git archive --format=tar.gz HEAD". It passes with --prefix=pharn-oss/ added, which is the documented form, and case (d) shows why that flag is needed.

Tests

  • tests/commands/verify-archive.test.ts (new, 21 cases, through the harness):
    • passes on a good archive, and on one carrying the v7.25.5 shape (an unlisted symlink, hard link and pax header);
    • refuses, naming the entry and rule: a hash mismatch, a symlink at a listed path, no manifest, a rootless archive, a deeper prefix, an --expect-version mismatch, a malformed MIN_CLI, a non-gzip file;
    • the PHARN_DEBUG hint and dump;
    • input paths: missing, a directory, a FIFO, over 32 MiB, empty, a symlinked file, and control characters in the path;
    • fetch is never called, and the temp dir is gone on a pass and on a fail.
  • cli-args (parse and refusals, help), index (dispatch), repo (verifyLocalArchive cleanup), skills-version (assertSkillsVersion), and dist-smoke (the bundle passes a fixture and refuses a missing file).
  • tests/support/tar-fixture.ts: an optional opts argument (extra or replaced raw entries, rootless). Existing callers get identical bytes.
  • tests/release-consistency.test.ts: v0.21.6 joins KNOWN_TAGS. That tag exists now, and [0.22.0] compares from it.
  • No existing test title was renamed or removed.

Local gates: test, validate, lint, format:check, lint:md, typecheck and build are all 0. Coverage 98.59 / 95.77 / 99.08 / 99.07. Regress against f9fa96b0 found no regressions. Records are in .dev/features/core-387-verify-archive/.

Version 0.22.0 (minor: a new command), with a CHANGELOG [0.22.0] section above [0.21.6]. This will conflict with #447 (0.21.7) on package.json, the lockfile, CHANGELOG and release-consistency, whichever merges first.

🤖 Generated with Claude Code

PrzemekGalarowicz and others added 9 commits November 25, 2026 17:31
… other entry (CORE-386)

pharn-oss v7.25.3-v7.25.5 commit seven symlinks under .claude/skills/, outside
pharn-install.json, and the extractor refused any non-file entry anywhere in the
archive, so every init/add/update/status failed on every channel.

The extractor now selects, then judges: two streamed passes over the archive
write only the files the CLI reads itself (CLONE_READ_FILES) and then, once the
manifest has validated, only the paths it lists. Every other entry is skipped
and never written, whatever its type or name. A listed path keeps every rule
(regular file, strict UTF-8, no control/format char, no absolute/../\/:, one
root, no duplicate) and a pax/GNU-modified entry at a listed path is refused;
verifyUpstreamManifest still fails a listed file that is missing or altered.
The tar is streamed through createGunzip, so the 128 MB cap now bounds bytes
written; headers (200k) and decompressed bytes (1 GiB) bound the walk.
extractPharnArchive takes a buffer, for a later local verify-archive mode.

Docs (CLAUDE.md, architecture, contributing, SECURITY, THREAT-MODEL via the
user's patch) and CHANGELOG [Unreleased] updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… (CORE-386)

Bump to 0.21.6 (epic-coordinated) and move the CORE-386 entry into the
[0.21.6] CHANGELOG section; v0.21.5 joins KNOWN_TAGS.

pharn-ci TI02 read the restructured tar-extract tests as removals. The tests
keep their base names now (the same behaviour, re-expressed against the
selection), with the old merged g-header and BOM cases split back out. The
init test is back to its base text: the new marker message still contains it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pharn-ci TI02 still read eight base tests as removed (computed it.each names
match by body). They are back with their base bodies: a test-level LIMITS
selects every path they use (latin1 keys), so each entry is judged by the full
rules exactly as before. A rootless entry named like a selected path is now
refused ("no path below the archive root") rather than skipped, which restores
"rejects a file with no component to strip". CLAUDE.md no longer names
pharn-install.json as a repo path (pharn-ci SETUP_STALE_SI02).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…CORE-386)

The refusal of a listed file after a modifier header now names that header's
type through describeTypeflag ("unsupported type 'x' (a pax extended
header, ...)"), so the base pax test keeps its expected value. The base test
"bounds the bytes written by the decompressed size" keeps its name, now over
the streamed decompressed cap (maxScannedBytes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tall would (CORE-387)

A new read-only command for pharn-oss CI: it runs the install path's own
extractPharnArchive (both passes, manifest validation, every listed sha256)
over a local .tar.gz, plus the capability-index build and a MIN_CLI validity
check, with no network, no project and no lock, in one private temp dir that
verifyLocalArchive (repo.ts) always removes. --expect-version X.Y.Z holds
SKILLS_VERSION to a version through assertSkillsVersion, the helper the
release check in fetchAt now shares. The input is read bounded (regular file,
32 MiB, no FIFO hang). The archive needs one top-level directory
(git archive --prefix=pharn-oss/); a rootless one gets a message naming it.

Version 0.22.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s-only' into feat/core-387-verify-archive

# Conflicts:
#	CHANGELOG.md
#	package-lock.json
#	package.json
…actor's rootless refusal (CORE-387)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…archive

# Conflicts:
#	CHANGELOG.md
#	package-lock.json
#	package.json
#	src/lib/repo.ts
#	tests/release-consistency.test.ts
#	tests/repo.test.ts
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 13 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 5ed3424 and de4dcf1.

Files ignored due to path filters: 9

  • .dev/features/core-387-verify-archive/GRILL.md is excluded by !.dev/**
  • .dev/features/core-387-verify-archive/PLAN.md is excluded by !.dev/**
  • .dev/features/core-387-verify-archive/REGRESSION.md is excluded by !.dev/**
  • .dev/features/core-387-verify-archive/REVIEW.md is excluded by !.dev/**
  • .dev/features/core-387-verify-archive/SHIP.md is excluded by !.dev/**
  • .dev/features/core-387-verify-archive/VERIFY.md is excluded by !.dev/**
  • .dev/features/core-387-verify-archive/regression-report.json is excluded by !.dev/**
  • .dev/features/core-387-verify-archive/verify-report.json is excluded by !.dev/**
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing: 23

  • AGENTS.md
  • CHANGELOG.md
  • CLAUDE.md
  • README.md
  • docs/README.md
  • docs/architecture.md
  • docs/commands/verify-archive.md
  • docs/contributing.md
  • docs/troubleshooting.md
  • package.json
  • src/commands/verify-archive.ts
  • src/index.ts
  • src/lib/cli-args.ts
  • src/lib/repo.ts
  • src/lib/skills-version.ts
  • tests/cli-args.test.ts
  • tests/commands/verify-archive.test.ts
  • tests/dist-smoke.test.ts
  • tests/index.test.ts
  • tests/release-consistency.test.ts
  • tests/repo.test.ts
  • tests/skills-version.test.ts
  • tests/support/tar-fixture.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

pharn

🛡️ pharn-ci · ⚠️ Warn

Warning

Warn · Diff coverage of this change is 100% against a threshold of 80%; 1 test-integrity finding; 33 agent setup files found.

Verdict Diff coverage Test integrity Agent setup
⚠️ Warn 100% (threshold 80%) ⚠️ 1 finding 33 files

🧪 Diff coverage

▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰ 100%

100% of changed lines covered (61/61, threshold 80%)

Changed files (5)
File Coverage Covered Uncovered lines
src/commands/verify-archive.ts 100% 40/40
src/index.ts 100% 3/3
src/lib/cli-args.ts 100% 7/7
src/lib/repo.ts 100% 9/9
src/lib/skills-version.ts 100% 2/2

🔍 Test integrity

  • ⚠️ TI12 tests/index.test.ts:43 — vi.mock("../src/commands/verify-archive.js") replaces src/commands/verify-archive.ts, a source file this change also edits, so the test may not run the code under review.
    • Hint: Ask a reviewer to confirm that mocking the changed module still tests its real behaviour.
Tests changed: +32 −0 ~0
Test file Added Removed Modified Renamed
tests/cli-args.test.ts 3 0 0 0
tests/commands/verify-archive.test.ts 22 0 0 0
tests/dist-smoke.test.ts 1 0 0 0
tests/repo.test.ts 3 0 0 0
tests/skills-version.test.ts 3 0 0 0

🤖 Agent setup (33 files)

Agent setup: 33 files · amp, claude-code, codex, copilot, cursor, jules, opencode, zed

Agent setup files (33)
Path Kind
.claude/commands/pharn-dev-build.md claude-command
.claude/commands/pharn-dev-eval.md claude-command
.claude/commands/pharn-dev-grill.md claude-command
.claude/commands/pharn-dev-memory-promote.md claude-command
.claude/commands/pharn-dev-plan.md claude-command
.claude/commands/pharn-dev-regress.md claude-command
.claude/commands/pharn-dev-review.md claude-command
.claude/commands/pharn-dev-ship.md claude-command
.claude/commands/pharn-dev-verify.md claude-command
.claude/hooks/enforce-writes-scope.cjs claude-hook
.claude/hooks/enforce-writes-scope.test.cjs claude-hook
.claude/hooks/git-worktree-fixture.cjs claude-hook
.claude/hooks/protect-trusted-paths.cjs claude-hook
.claude/hooks/protect-trusted-paths.test.cjs claude-hook
.claude/hooks/session-root.cjs claude-hook
.claude/hooks/session-root.test.cjs claude-hook
.claude/hooks/set-writes-scope.cjs claude-hook
.claude/hooks/set-writes-scope.test.cjs claude-hook
.claude/settings.json claude-settings
.claude/skills/phargus-diagnose claude-skill
.claude/skills/phargus-memory claude-skill
.claude/skills/phargus-rules claude-skill
.claude/skills/phargus-setup claude-skill
.claude/skills/phargus-verify claude-skill
.claude/skills/pharn-ci-cover claude-skill
.claude/skills/pharn-ci-explain claude-skill
.claude/skills/pharn-ci-fix claude-skill
.claude/skills/pharn-ci-install claude-skill
.claude/skills/pharn-ci-policy claude-skill
.claude/skills/pharn-cli claude-skill
.claude/skills/security-audit claude-skill
AGENTS.md agents-md
CLAUDE.md claude-md

pharn-ci 0.12.0 · report schema v2 · coverage format lcov

…sal failure (CORE-387)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PrzemekGalarowicz

Copy link
Copy Markdown
Member Author

On the pharn-ci warnings:

  • TI03 (the skip on the FIFO case) is fixed in 09aa347. The case now runs unskipped, as the FIFO case in tests/bounded-read.test.ts does; the gates run on ubuntu only.
  • TI12 (tests/index.test.ts mocks src/commands/verify-archive.js) is the established pattern. index.test.ts replaces every command module to observe dispatch, and CLAUDE.md names it as the one suite allowed to vi.mock src. The real runVerifyArchive is run unmocked by tests/commands/verify-archive.test.ts (22 cases) and by the dist-smoke bundle case. A reviewer who is not the PR author would need to confirm this.
  • The uncovered line 81 (a failure that is not an archive refusal) is now covered (TMPDIR pointing at a missing directory).

…archive

# Conflicts:
#	CHANGELOG.md
#	docs/troubleshooting.md
#	package-lock.json
#	package.json
#	tests/repo.test.ts
#	tests/support/tar-fixture.ts
@PrzemekGalarowicz
PrzemekGalarowicz merged commit 22fa7a9 into main Nov 25, 2026
15 checks passed
@PrzemekGalarowicz
PrzemekGalarowicz deleted the feat/core-387-verify-archive branch November 25, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant